package com.jianhua.backend.controller;

import com.jianhua.backend.common.R;
import com.jianhua.backend.domain.dto.PackageSQDto;
import com.jianhua.backend.domain.entity.MealPackages;
import com.jianhua.backend.domain.entity.PackageSQ;
import com.jianhua.backend.service.MealPackagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/meal-packages")
public class MealPackagesController {

    private final MealPackagesService mealPackagesService;

    @Autowired
    public MealPackagesController(MealPackagesService mealPackagesService) {
        this.mealPackagesService = mealPackagesService;
    }

    // 获取所有套餐
    @GetMapping("/all")
    public List<MealPackages> getAllPackages() {
        return mealPackagesService.getAllPackages();
    }

    // 根据ID获取套餐详情
    @GetMapping("/{id}")
    public MealPackages getPackageById(@PathVariable Integer id) {
        return mealPackagesService.getPackageById(id);
    }

    // 创建套餐
    @PostMapping("/add")
    public void createPackage(@RequestBody MealPackages mealPackage) {
        mealPackagesService.createPackage(mealPackage);
    }

    // 更新套餐
    @PutMapping("/update")
    public void updatePackage(@RequestBody MealPackages mealPackage) {
        mealPackagesService.updatePackage(mealPackage);
    }

    // 删除套餐
    @DeleteMapping("/{id}")
    public void deletePackage(@PathVariable Integer id) {
        mealPackagesService.deletePackage(id);
    }

    @PostMapping("/list")
    public R getMealPackages(@RequestBody PackageSQDto packageSQDto){
        List<PackageSQ> mealPackages = mealPackagesService.getMealPackages(packageSQDto);
        return R.success(mealPackages);
    }
}
